unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure CirclePoints(x, y : integer);
    procedure MidPointCircle(r : integer);
    procedure FormPaint(Sender: TObject);
    procedure FloodFill4(x, y : integer; OldColor, NewColor : TColor);
    procedure Button1Click(Sender: TObject);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  x0, y0, r : integer;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.CirclePoints(x, y: integer);
begin
  Canvas.MoveTo(x0+x, y0+y); Canvas.LineTo(x0+x, y0+y);
  Canvas.MoveTo(x0+y, y0+x); Canvas.LineTo(x0+y, y0+x);
  Canvas.MoveTo(x0+y, y0-x); Canvas.LineTo(x0+y, y0-x);
  Canvas.MoveTo(x0+x, y0-y); Canvas.LineTo(x0+x, y0-y);
  Canvas.MoveTo(x0-x, y0-y); Canvas.LineTo(x0-x, y0-y);
  Canvas.MoveTo(x0-y, y0-x); Canvas.LineTo(x0-y, y0-x);
  Canvas.MoveTo(x0-y, y0+x); Canvas.LineTo(x0-y, y0+x);
  Canvas.MoveTo(x0-x, y0+y); Canvas.LineTo(x0-x, y0+y);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  x0 := 200;
  y0 := 200;
  r := 100;
  Canvas.Pen.Color := clred;
  Canvas.Pen.Width := 2;
end;

procedure TForm1.MidPointCircle(r: integer);
var
  i, x, y : integer;
  d : real;
begin
  x := 0;
  y := r;
  d := 1.25 - r;
  CirclePoints(x,y);
  while x<=y do
  begin
    if d<0 then
    begin
      d := d + 2*x +3;
    end
    else
    begin
      d := d + 2*(x-y)+5;
      y := y - 1;
    end;
    Inc(x);
    CirclePoints(x,y);
  end;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  MidPointCircle(r);
end;

procedure TForm1.FloodFill4(x, y: integer; OldColor, NewColor: TColor);
begin
  if Canvas.Pixels[x,y]=OldColor then
  begin
    Canvas.Pixels[x,y] := NewColor;
    FloodFill4(x,y+1,OldColor,NewColor);
    FloodFill4(x,y-1,OldColor,NewColor);
    FloodFill4(x-1,y,OldColor,NewColor);
    FloodFill4(x+1,y,OldColor,NewColor);
  end;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FloodFill4(200, 200, clBtnFace, clGreen);
  FormPaint(Sender);
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  Label1.Caption := 'X = ' + IntToStr(X);
  Label2.Caption := 'Y = ' + IntToStr(Y);
end;

end.
